package quartz_exercise.simpleexercise;


import lombok.Data;
import org.quartz.*;

import java.text.SimpleDateFormat;
import java.util.Date;
@Data
public class SimpleJob implements Job {

    private SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    private String name;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {

        System.out.println("定时任务启动:"+sf.format(new Date()));

        JobDetail jobDetail = jobExecutionContext.getJobDetail();
        String description = jobDetail.getDescription();
        System.out.println(description);

        JobDataMap jobDataMap = jobDetail.getJobDataMap();

        System.out.println("通过属性接收传递的参数是："+this.name);
        String nowTime = jobDataMap.getString("nowTime");
        System.out.println("通过Map接收传过来的参数，项目开始时间是;"+nowTime);
        Trigger trigger = jobExecutionContext.getTrigger();
        Date endTime = trigger.getEndTime();
        System.out.println("通过触发器获得结束时间："+sf.format(endTime));
        System.out.println("=============================================");

    }


}
